/*
    www.cguage.com
    1.1 找最长连续串
    优化思路: 判断arr[i] ?= arr[i - maxLength]
*/

#include <iostream>
#include <sstream>
#include <cassert>
#include <vector>
using namespace std;

#ifndef TEST
#define IN(iss) {                       \
        std::string str;                \
        std::getline(std::cin, str);    \
        iss.str(str);                   \
    }
#define OUT(s) std::cout << s
#endif

#define READ_N(iss, n) {    \
    iss >> n;               \
    iss.ignore(1, ',');     \
}

int main() {
    istringstream iss;
    IN(iss);

    // 解析到数组
    vector<int> inputNumList;
    int n = 0;
    while (!iss.eof()) {
        READ_N(iss, n);
        inputNumList.push_back(n);
    }

    assert(!inputNumList.empty());

    // 采用推测的方法找最大长度
    // arr[i] ?= arr[i - len]
    int rstNum = inputNumList[0];
    int maxTimes = 1;
    for (int i = 1; i < inputNumList.size(); ++i) {
        if (inputNumList[i] == inputNumList[i - maxTimes]) {
            rstNum = inputNumList[i];
            ++maxTimes;
        }
    }

    // 把结果组装成序列
    ostringstream oss;
    for (int i = 0; i < maxTimes - 1; ++i) {
        oss << rstNum << ",";
    }
    oss << rstNum;
    OUT(oss.str());
    return 0;
}

#ifdef TEST
struct TestCase CASES[] = {
    /*0*/{"1,2,2,3,3,3,4,5,5,6", "3,3,3"},
    /*1*/{"1,2,3,4,5", "1"},
    /*2*/{"-1,-1,-1,0,2,2", "-1,-1,-1"},
};
#endif